<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Adicionar Requisito</title>

<script type="text/javascript">
var selected = [],
acao,
win,
ADICIONA_RESPONSAVEL = 1;
ADICIONA_PROJETO = 2;

jsool.onReady(function(){

	jsool
    .get("adicionaResponsavel")
	     .on("click",function(ev1){
	    	acao = ADICIONA_RESPONSAVEL;
	    	if(!win || win.closed){
				win = window.open('/requisiteworks/funcionario/util/pesquisar.do'
					,"selectFuncionario"
					,'width=500,height=400,directories=no,location=no,menubar=no,resizable=0,scrollbars=1,status=no,toolbar=no'
					,true);
			}
			win.focus();
	});

	jsool
    .get("adicionaProjeto")
	     .on("click",function(ev2){
	    	acao = ADICIONA_PROJETO;
	    	if(!win || win.closed){
				win = window.open('/requisiteworks/projeto/util/pesquisar.do'
					,"selectProjeto"
					,'width=500,height=400,directories=no,location=no,menubar=no,resizable=0,scrollbars=1,status=no,toolbar=no'
					,true);
			}
			win.focus();
	});	
});

function onSelect(proj){
	if (acao == ADICIONA_RESPONSAVEL) {
   	  	  jsool.get("numeroResponsavel").set("value",proj.numero);
		  jsool.get("nomeResponsavel").set("value",proj.nome);
	}
	if (acao == ADICIONA_PROJETO) {
	   	  jsool.get("numeroProjeto").set("value",proj.numero);
		  jsool.get("nomeProjeto").set("value",proj.nome);
	}
}

</script>

</head>
<body>
	<fieldset>
			<legend>Novo Requisito</legend>
			
			<form:form modelAttribute="requisito"  action="/requisiteworks/requisito/adicionar.do" method="POST">
				<table class="form">
					<tr>
						<td>
							<form:label path="nome" cssErrorClass="erro">Nome</form:label>
						</td>
						<td>
							<form:input path="nome" cssErrorClass="erro" maxlength="128"/>
						</td>
						<td>
							<ul>
								<form:errors path="nome" cssClass="erro" element="li"></form:errors>
							</ul>
						</td>
					</tr>
					
					<tr>
						<td>
							<form:label path="estado" cssErrorClass="erro">Estado: </form:label>
						</td>
						<td>
							<select name="estado">								
								<c:forEach items="${estadoList}" var="estado">
									<option value="${estado}">${estado}</option>
								</c:forEach>
							</select>
						</td>
					</tr>
					
					<tr>
						<td>
							<form:label path="responsavel.numero" cssErrorClass="erro">Responsavel: </form:label>
						</td>
						<td>
							<form:hidden path="responsavel.numero" id="numeroResponsavel"/>
							<form:input path="responsavel.nome" id="nomeResponsavel" disabled="true" />
							<img id="adicionaResponsavel" style="display: inline;" align="top" src="/requisiteworks/images/add.png" alt="IncluirResponsavel"/>							
						</td>
						<td>
							<ul>
								<form:errors path="responsavel.numero" cssClass="erro" element="li"></form:errors>
							</ul>
						</td>
					</tr>
					
					<tr>
						<td>
							<form:label path="projeto.numero" cssErrorClass="erro">Projeto: </form:label>
						</td>
						<td>
							<form:hidden path="projeto.numero" id="numeroProjeto"/>
							<form:input path="projeto.nome" id="nomeProjeto" disabled="true" />
							<img id="adicionaProjeto" style="display: inline;" align="top" src="/requisiteworks/images/add.png" alt="IncluirProjeto"/>							
						</td>
						<td>
							<ul>
								<form:errors path="projeto.numero" cssClass="erro" element="li"></form:errors>
							</ul>
						</td>
					</tr>
			</table>
				<button type="submit">Salvar</button>
			</form:form>
		</fieldset>
</body>
</html>